package com.googlecode.astoolkit {
	
	import com.googlecode.astoolkit.events.GotoEvent;
	import com.googlecode.astoolkit.events.TitleEvent;
	import com.googlecode.astoolkit.utils.Sitemap;
	
	import flash.events.EventDispatcher;

	public class FrankyApi extends EventDispatcher {
		
		private static var _instance:FrankyApi;
		//private static var _model:ContentModel = ContentModel.getInstance();
		private static var _sitemap:Sitemap = Sitemap.getInstance();

		public function FrankyApi(singletonenforcer:SingletonEnforcer){
			 if(singletonenforcer == null){
				throw new Error("FrankyApi es un Singleton. Para acceder a una instancia hacedlo mediante .getInstance()");
			} 
        }
        
        public static function getInstance():FrankyApi{
           if(!_instance){
               _instance = new FrankyApi(new SingletonEnforcer());
           }
           return _instance;
        } 
		
		public static function goto(link:String, params:Object=null):void{
			FrankyApi.getInstance().dispatchEvent(new GotoEvent(link, params));
		}
		
		//
		public static function addEventListener(type:String, listener:Function, useCaptureBoolean:Boolean=false, priority:int=0, useWeakReference:Boolean=false):void{
			FrankyApi.getInstance().addEventListener(type, listener, useCaptureBoolean, priority, useWeakReference);
		} 
		
		//
		public static function removeEventListener(type:String, listener:Function, useCaptureBoolean:Boolean=false):void{
			FrankyApi.removeEventListener(type, listener, useCaptureBoolean);
		} 
		
		public static function hasEventListener(type:String):Boolean{
			return FrankyApi.hasEventListener(type);
		} 
		
		// Getterde _datos
		public static function get xml():XML {
			return Sitemap.xml;
		}

		// Getter de _nodes
		public static function get nodes():Array {
			return Sitemap.nodes;
		}

		// Getter de _path
		/* public static function get path():String {
			return Sitemap..path;
		} */

		// Getter Setter de _pathNames
		/* public static function get pathNames():Array {
			return _model.pathNames;
		} */

		/* public static function get pathIds():IIterator {
			return _model.pathIds;
		} */

		// Getter y Setter de _params
		/* public static function get params():ParamsObject {
			return _model.params;
		} */
		
		//
		public static function set title(title:String):void{
			//trace("title-->" + title);
			FrankyApi.getInstance().dispatchEvent(new TitleEvent(title));
		}
		
		//
		/* private static function listenerHandler(e:Event):void{
			trace("e-->" + e.target);
			//dispatchEvent(e);
		} */
	}
}

class SingletonEnforcer{}
